package unit15.randomAccess;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.io.Serializable;

public class DataIO implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 300532531301749302L;
	public static void writeFixedString(String s,int size,DataOutput out) throws IOException{
		for(int x=0;x<size;x++){
			char ch=0;
			if(x<s.length())
				ch=s.charAt(x);
			out.writeChar(ch);
		}
	}
	public static String readFixedString(int size,DataInput in) throws IOException{
		StringBuilder sb=new StringBuilder(size);
		int x=0;
		boolean more=true;
		while(more&&x<size){
			char ch=in.readChar();
			x++;
			if(ch==0)
				more=false;
			else
				sb.append(ch);
		}
		in.skipBytes(2*(size-x));
		return sb.toString();
	}
}
